﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:AdminApi="clr-namespace:Microsoft.ApplicationServer.Caching.AdminApi;assembly=Microsoft.ApplicationServer.Caching.Management" 
    xmlns:MDCAdminTool="clr-namespace:MDCAdminTool;assembly=E4D.AppFabric.Entities" 
    xmlns:Caching="clr-namespace:Microsoft.ApplicationServer.Caching;assembly=Microsoft.ApplicationServer.Caching.Core" 
    xmlns:E4D="clr-namespace:MDCAdminTool">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Images.xaml" />        
    </ResourceDictionary.MergedDictionaries>

    <E4D:DebugConverter x:Key="DebugConverter"/>
    <E4D:TimeSpanConverter x:Key="TimeSpanConverter"/>

    <HierarchicalDataTemplate 
        DataType="{x:Type MDCAdminTool:CacheRegion}" 
        ItemsSource="{Binding CacheItems, Mode= OneWay,IsAsync=True}">

        <StackPanel Orientation="Horizontal">
            <Image Source="..\Resources\Region.png" Height="16" Width="16"  Margin="0,0,3,0"/>
            <TextBlock>
                Region: 
                <TextBlock Text="{Binding Name}" FontWeight="Bold"/>
                <TextBlock Text="{Binding CacheItemsCount,Mode=OneWay,StringFormat=(#)}" FontWeight="Bold"/>                
                <TextBlock.ContextMenu>
               <ContextMenu>                 
                  <MenuItem Header="Remove Cache Region" Command="{StaticResource RemoveRegionCacheName}" CommandParameter="{Binding}" Icon="{StaticResource RemoveCache16}"/>                   
                  <MenuItem Header="Add Cache Region"    Command="{StaticResource AddRegionCacheName}"    CommandParameter="{Binding}" Icon="{StaticResource AddRegionCacheName16}"/>
                  <MenuItem Header="Get Cache Items"    Command="{StaticResource GetObjectsInRegionCommand}"    CommandParameter="{Binding}" Icon="{StaticResource AddRegionCacheName16}"/>
                  <MenuItem Header="Add Data Cache Item"  Command="{StaticResource AddDataCacheItemCommand}" CommandParameter="{Binding}" Icon="{StaticResource DataCacheItem16}"/>
               </ContextMenu>
            </TextBlock.ContextMenu>
            </TextBlock>
        </StackPanel>

    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate DataType="{x:Type Caching:DataCacheItem}" >
        <TextBlock Text="{Binding Key}" />
    </HierarchicalDataTemplate>
    
    
    <DataTemplate x:Key="CacheRegionContentTemplate" 
                 DataType="{x:Type MDCAdminTool:CacheRegion}">
        <GroupBox Padding="15">
            <ScrollViewer>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="3*" />
                        <RowDefinition Height="20*" />
                        <!--<RowDefinition Height="30*" />-->
                    </Grid.RowDefinitions>

                    <StackPanel x:Name="spTitle" Grid.Row="0" Orientation="Horizontal" Margin="15,0,0,0">
                        <StaticResource ResourceKey="RegionCacheName"/>
                        <TextBlock Text="{Binding Name}" FontSize="32" FontWeight="Bold" Margin="15,0,0,0" />
                        <TextBlock x:Name="HeaderText" Text=" Region" FontSize="32" FontWeight="Bold" />
                    </StackPanel>

                    <StackPanel Grid.Row="1" Margin="15">
                        <GroupBox Padding="15" Margin="0,0,0,25">
                            <GroupBox.Header>
                                <StackPanel Orientation="Horizontal">
                                    <StaticResource ResourceKey="GetHostConfig16" />
                                    <TextBlock Text="Region Info" Margin="5,0,0,0"/>
                                </StackPanel>
                            </GroupBox.Header>
                            
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Name:" Margin="5,0,10,0"/>
                                <TextBlock Text="{Binding Name }" FontWeight="Bold" Margin="5,0,10,0"/>

                                <TextBlock Text="Role:" Margin="5,0,10,0"/>
                                <TextBlock Text="{Binding Role }" FontWeight="Bold" Margin="5,0,10,0"/>

                                <TextBlock Text="Port No:" Margin="5,0,10,0"/>
                                <TextBlock Text="{Binding PortNo }" FontWeight="Bold" Margin="5,0,10,0"/>
                            </StackPanel>
                        </GroupBox>

                        <GroupBox Padding="15">
                            <GroupBox.Header>
                                <StackPanel Orientation="Horizontal">
                                    <StaticResource ResourceKey="CacheHostStatistics16" />
                                    <TextBlock Text="Data Cache Items" Margin="5,0,0,0"/>
                                </StackPanel>
                            </GroupBox.Header>
                            <Grid >

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <!--<Label Content="Item Count:" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                                <Label Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="3" Name="itemCountTextBox" Content="{Binding Path=CacheItems.Count}" VerticalAlignment="Center" Width="120" />
                                <Label Content="Miss Count:" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                                <Label Grid.Column="3" Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="3" Name="missCountTextBox" Content="{Binding Path=CacheRegionStats.MissCount}" VerticalAlignment="Center" Width="120" />

                                <Label Content="Region Name:" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                                <Label Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="3" Name="regionCountTextBox" Content="{Binding Path=CacheRegionStats.RegionName}" VerticalAlignment="Center" Width="120" />
                                <Label Content="Request Count:" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                                <Label Grid.Column="3" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="3" Name="requestCountTextBox" Content="{Binding Path=CacheRegionStats.RequestCount}" VerticalAlignment="Center" Width="120" />

                                <Label Content="Size:" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
                                <Label Grid.Column="1" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="3" Name="sizeTextBox" Content="{Binding Path=CacheRegionStats.Size}" VerticalAlignment="Center" Width="120" />-->

                                <DataGrid 
                                    Grid.Column="0"  
                                    Grid.ColumnSpan="4" Grid.Row="0" 
                                    AutoGenerateColumns="False" HorizontalAlignment="Stretch"
                                    ItemsSource="{Binding CacheItems, IsAsync=True}" >
                                    <DataGrid.Columns>
                                        <DataGridTextColumn Binding="{Binding Key}"     Header="Key" MinWidth="100"/>
                                        <DataGridTextColumn Binding="{Binding Value}"   Header="Value" MinWidth="100" MaxWidth="500"/>
                                        <DataGridTemplateColumn Header="Tags" MinWidth="100">
                                            <DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <ItemsControl ItemsSource="{Binding Tags}">
                                                        <ItemsControl.ItemsPanel>
                                                            <ItemsPanelTemplate>
                                                                <WrapPanel Orientation="Horizontal"/>
                                                            </ItemsPanelTemplate>
                                                        </ItemsControl.ItemsPanel>
                                                    </ItemsControl>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellTemplate>
                                        </DataGridTemplateColumn>
                                        <DataGridTextColumn Binding="{Binding Path=Timeout,Converter={StaticResource TimeSpanConverter}}" Header="Timeout" />
                                    </DataGrid.Columns>
                                </DataGrid>

                            </Grid>
                        </GroupBox>
                    </StackPanel>



                    <!--<StackPanel x:Name="spFooter" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,15,0">
                  <Button Height="23" Width="75" Margin="5,0,5,0" Content="Cancel" Command="{StaticResource TabClose}"/>
                  <Button Height="23" Width="75" Margin="5,0,5,0" Content="Save" Command="{StaticResource SaveCacheName}" CommandParameter="{Binding}"/>
               </StackPanel>-->
                </Grid>
            </ScrollViewer>
        </GroupBox>
    </DataTemplate>

    <DataTemplate DataType="{x:Type AdminApi:RegionInfo}" >
        <StackPanel Orientation="Horizontal">

            <TextBlock Text="Host Name:" Margin="5,0,10,0"/>
            <TextBlock Text="{Binding HostName }" FontWeight="Bold" Margin="5,0,10,0"/>

            <TextBlock Text="Cache Name:" Margin="5,0,10,0"/>
            <TextBlock Text="{Binding CacheName }" FontWeight="Bold" Margin="5,0,10,0"/>

            <TextBlock Text="Port No:" Margin="5,0,10,0"/>
            <TextBlock Text="{Binding PortNo }" FontWeight="Bold" Margin="5,0,10,0"/>

            <TextBlock Text="Region Name:" Margin="5,0,10,0"/>
            <TextBlock Text="{Binding RegionName }" FontWeight="Bold" Margin="5,0,10,0"/>

            <TextBlock Text="Role:" Margin="5,0,10,0"/>
            <TextBlock Text="{Binding Role }" FontWeight="Bold" Margin="5,0,10,0"/>

        </StackPanel>
    </DataTemplate>

</ResourceDictionary>